package com.shigi.knapsack.solvers.ga;

import com.shigi.knapsack.KnapsackItem;

/**
 * Created by Miroslav Šiagi on 01/12/14.
 */
public class KnapsackIndividual {
    private KnapsackItem[] knapsackItems;
    private double fitnessValue;

    public KnapsackIndividual(int numberOfItems) {
        this.knapsackItems = new KnapsackItem[numberOfItems];
    }

    public KnapsackIndividual(KnapsackIndividual anotherKnapsackIndividual) {
        KnapsackItem[] anoterKnapsackItems = anotherKnapsackIndividual.getKnapsackItems();
        int numOfItems = anoterKnapsackItems.length;

        KnapsackItem[] newItems = new KnapsackItem[numOfItems];
        for (int j = 0; j < numOfItems; j++) {
            KnapsackItem knapsackItem = new KnapsackItem(anoterKnapsackItems[j].getId());
            knapsackItem.setUsed(anoterKnapsackItems[j].isUsed());
            knapsackItem.setWeight(anoterKnapsackItems[j].getWeight());
            knapsackItem.setValue(anoterKnapsackItems[j].getValue());
            newItems[j] = knapsackItem;
        }
        this.knapsackItems = newItems;
    }

    public KnapsackItem[] getKnapsackItems() {
        return knapsackItems;
    }

    public void setKnapsackItems(KnapsackItem[] knapsackItems) {
        this.knapsackItems = knapsackItems;
    }

    public double getFitnessValue() {
        return fitnessValue;
    }

    public void setFitnessValue(double fitnessValue) {
        this.fitnessValue = fitnessValue;
    }
}
